//
//  SettingsScreen.m
//  iSudoku
//
//  Created by Tri Vo on 5/18/13.
//  Copyright (c) 2013 Tri Vo. All rights reserved.
//

#import "SettingsScreen.h"
#import "GameUtils.h"

@implementation SettingsScreen

+ (id)scene {
    CCScene *scene = [CCScene node];
    SettingsScreen *setting = [SettingsScreen node];
    [scene addChild:setting];

    return scene;
}

- (id)init {
    self = [super init];
    if (self) {
        // Do something here
    }
    return self;
}

- (void)dealloc {
    [super dealloc];
}

#pragma mark - Screen Methods

- (void)onEnter {
    NSString *keyValue = [[GameUtils getInstance] getValueForKey:@""];
    // Title
    [m_lblTitle setString:keyValue];
    // Sound
    // Music
    // Language
    keyValue = [[GameUtils getInstance] getValueForKey:@""];
    [m_lblLanguage setString:keyValue];
    if ([[[GameUtils getInstance] getCurrentLanguage] isEqualToString:@"en"]) {
        [m_btnLanguage setBackgroundSpriteFrame:nil forState:CCControlStateNormal];
    } else {
        [m_btnLanguage setBackgroundSpriteFrame:nil forState:CCControlStateNormal];
    }
    // Back
    keyValue = [[GameUtils getInstance] getValueForKey:@"Game_Back"];
    [m_btnBack setTitle:keyValue forState:CCControlStateNormal];
}

#pragma mark - Screen events

- (void) setSoundON:(id)sender {
    BOOL soundPref = [[GameUtils getInstance] isSoundOn];
    if (soundPref) {
        soundPref = NO;
    } else {
        soundPref = YES;
    }
    [[GameUtils getInstance] setSoundOn:soundPref];
//    [_menuSound setString:[NSString stringWithFormat:@"Sound: %@", soundPref ? @"YES" : @"NO"]];
}

- (void) setMusicON:(id)sender {
    BOOL musicPref = [[GameUtils getInstance] isMusicOn];
    if (musicPref) {
        musicPref = NO;
    } else {
        musicPref = YES;
    }
    [[GameUtils getInstance] setMusicOn:musicPref];
//    [_menuMusic setString:[NSString stringWithFormat:@"Music: %@", musicPref ? @"YES" : @"NO"]];
}


- (void) changeLanguage:(id)sender {
    BOOL isEng = YES;
    if ([[[GameUtils getInstance] getCurrentLanguage] isEqualToString:@"en"]) {
        isEng = NO;
    }
    [[GameUtils getInstance] setLanguage:isEng];
    [[GameUtils getInstance] loadLanguage];
}

#pragma mark - Touch Methods

- (void)ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
    
}


@end
